package com.andy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

@Controller
@RequestMapping("/demo")
public class DemoController {

    @RequestMapping("/getNewName")
    @ResponseBody
    public String getNewName(String name){
        String newName = "新名字为：new"+name;
        return newName;
    }

    @RequestMapping(value = "/getUser/{userId}",method = {RequestMethod.GET})
    @ResponseBody
    public String getUser(@PathVariable  int userId){
        String userName = "用户"+userId;
        return userName;
    }

    @RequestMapping("/getDate")
    public String getDate(Model model){
        model.addAttribute("date",new Date());
        return "success";
    }

    @RequestMapping("/zuosi")
    public String zuosi(){
        throw new RuntimeException("作死啊你");
    }

}
